//
//  IFIndexTitleCell.m
//  chanlin
//
//  Created by Ryan on 14-11-9.
//  Copyright (c) 2014年 chanlin. All rights reserved.
//

#import "IFIndexTitleCell.h"
#import "UIView+Utils.h"

@implementation IFIndexTitleCell

- (void)uiInit{
    [super uiInit];
    
    self.titleLabel = [[IFIndexTitleView alloc] initWithFrame:CGRectMake(cellEdgeCap, cellEdgeCap, cellLongTitleWidth, cellTitleHeight)];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.titleLabel.font = [UIFont systemFontOfSize:15.f];
   // self.titleLabel.numberOfLines = 2;
    self.titleLabel.textColor=RGB(0x56, 0x56, 0x5e);
    [self.baseView addSubview:self.titleLabel];
    
    self.cellSeperatorImgView=[CALayer layer];
    self.cellSeperatorImgView.frame=CGRectMake(0, 0.f, GlobleWidth, 0.5f);
    self.cellSeperatorImgView.backgroundColor=RGB(0xe0, 0xe0, 0xde).CGColor;
    [self.baseView.layer addSublayer:self.cellSeperatorImgView];
    
//    self.cellSeperatorImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0.f, GlobleWidth, 0.5f)];
//    [self.cellSeperatorImgView setNightBlock:^(UIView *me,BOOL isDay){
//        [((UIImageView *)me) setImage:[UIImage imageNamed:(isDay?@"seperator_line.png":@"seperator_line_night.png")]];
//    }];
//    [self addSubview:self.cellSeperatorImgView];
    
    _anco = [[UIImageView alloc] initWithFrame:CGRectMake(self.titleLabel.left, 60.f, 14.f, 10.f)];
    [self.baseView addSubview:_anco];
    
    _styleIcon = [[UIImageView alloc] initWithFrame:CGRectMake(self.titleLabel.left, 60.f, 24.f, 11.f)];
    _styleIcon.contentMode=UIViewContentModeScaleAspectFit;
    [self.baseView addSubview:_styleIcon];
    
    
    self.liveStatusLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 60.f, 100.f, 11.f)];
    self.liveStatusLab.font = [UIFont systemFontOfSize:11.f];
    self.liveStatusLab.textAlignment = NSTextAlignmentLeft;
    self.liveStatusLab.textColor=RGB(0x84, 0x92, 0xa7);
    [self addSubview:self.liveStatusLab];
    
//    _liveStatus = [[UILabel alloc] initWithFrame:CGRectMake(_styleIcon.right + 5.f, _styleIcon.top, 100.f, 11.f)];
//    _liveStatus.font = [UIFont systemFontOfSize:11];
//    [_liveStatus setNightBlock:^(UIView *me,BOOL isDay){
//        [((IfengUILabel *)me) setTextColor:(isDay?RGB(0x84,0x92,0xa7):RGB(0x3b,0x42,0x4a))];
//    }];
//    [self addSubview:_liveStatus];
    
    _commentCountIcon = [[UIImageView alloc]initWithFrame:CGRectMake(GlobleWidth-47.f, 60.f, 12.f, 12.f)];
    _commentCountIcon.image = [UIImage imageNamed:@"index_commentCount_icon.png"];
    [self.baseView addSubview:_commentCountIcon];
    
    _commentCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(_commentCountIcon.right+4.f, 61.f, 40.f, 10.f)];
    _commentCountLabel.textAlignment = NSTextAlignmentLeft;
    _commentCountLabel.font = [UIFont fontWithName:@"Avenir-Book" size:10];
    _commentCountLabel.textColor=RGB(0x5b, 0x85, 0x9e);
    [self.contentView addSubview:_commentCountLabel];
    
    
    _commentIcon = [[UIImageView alloc] init];//WithFrame:CGRectMake(GlobleWidth-47.f, 60.f, 13.f, 11.f)];
    _commentIcon.image=[UIImage imageNamed:@"index_biaozhi.png"];
    

    [self.baseView addSubview:_commentIcon];
    
    _commentLable = [[UILabel alloc] init];//WithFrame:CGRectMake(_commentIcon.right+4.f, 60.f, 40.f, 12.f)];
    _commentLable.textAlignment = NSTextAlignmentLeft;
    _commentLable.font = [UIFont fontWithName:@"Avenir-Book" size:12];
    _commentLable.textColor=RGB(0x5b, 0x85, 0x9e);
    [self.contentView addSubview:_commentLable];
    
//    _sourceLable = [[IfengUILabel alloc] initWithFrame:CGRectMake(self.titleLabel.left, 58.f, 150.f, 12.f)];
//    _sourceLable.font = [UIFont systemFontOfSize:12];
//    [_sourceLable setNightBlock:^(UIView *me,BOOL isDay){
//        [((IfengUILabel *)me) setTextColor:(isDay?RGB(0x84,0x92,0xa7):RGB(0x3b,0x42,0x4a))];
//    }];
    [self.baseView addSubview:_sourceLable];

}

- (void)_commentIconStyle {
    float x=self.titleLabel.left;
    if (self.commentIcon.hidden == NO  && _anco.hidden == NO) {
        _commentIcon.frame = CGRectMake(_anco.right+8, 60.f, 13.f, 11.f);
        
        
    }else if (self.commentIcon.hidden == NO  && _styleIcon.hidden == NO) {
        _commentIcon.frame = CGRectMake(_styleIcon.right+8, 60.f, 13.f, 11.f);
        
    }else {
        _commentIcon.frame = CGRectMake(self.titleLabel.left, 60.f, 13.f, 11.f);
        
    }
    _commentLable.frame = CGRectMake(_commentIcon.right+4.f, 60.f, 40.f, 12.f);
    if(self.commentLable.hidden==NO){
        x=self.commentLable.right+8;
    }else if(_anco.hidden==NO){
        x=self.anco.right+8;
    }else if(_styleIcon.hidden == NO){
        x=_styleIcon.right+8;
    }
    
    self.liveStatusLab.left=x;
    
    
}

- (void)loadData:(CLList *)newsList{
    [super loadData:newsList];
    
    //self.indexList = indexList;
    self.titleLabel.text = newsList.title;
    [self hidenCompont];
    
    if(_isStrNotNull(newsList.sub)){
        self.commentLable.hidden=NO;
        self.commentIcon.hidden=NO;
        self.commentLable.text=newsList.sub;
    }
    
    if(newsList.comment && newsList.comment != 0 && newsList.comment>0){
        self.commentCountIcon.hidden=NO;
        self.commentCountLabel.hidden=NO;
    [self.commentCountLabel setText:[NSString stringWithFormat:@"%d",newsList.comment]];
    }
    
    if(newsList.link==CLList_sliders){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].slideIcon;
        _anco.width=13;
        
    }else if(newsList.link==CLList_video){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].videoIcon;
        _anco.width=13;
        
    }else if(newsList.link==CLList_topic){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].topciIcon;
        
    }else if(newsList.link==CLList_audio){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].audioIcon;
        _anco.width=14.5;
        
    }else if(newsList.link==CLList_live){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].liveIcon;

    }
    
    if(_isStrNotNull(newsList.status)){
        self.liveStatusLab.text=newsList.status;
        self.liveStatusLab.hidden=NO;
        
    }
    
    [self _commentIconStyle];

}

- (void)loadTopicData:(CLTopic *)newsList{
    [super loadTopicData:newsList];
    
    //self.indexList = indexList;
    self.titleLabel.text = newsList.title;
    [self hidenCompont];
    
    if(_isStrNotNull(newsList.sub)){
        self.commentLable.hidden=NO;
        self.commentIcon.hidden=NO;
        self.commentLable.text=newsList.sub;
    }
    
    if(newsList.comment && newsList.comment  != 0 && newsList.comment >0){
        self.commentCountIcon.hidden=NO;
        self.commentCountLabel.hidden=NO;
        [self.commentCountLabel setText:[NSString stringWithFormat:@"%d",newsList.comment]];
    }
    
    if(newsList.link==CLList_sliders){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].slideIcon;
        _anco.width=12;
        
    }else if(newsList.link==CLList_video){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].videoIcon;
        _anco.width=12;
        
    }else if(newsList.link==CLList_topic){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].topciIcon;
        
    }else if(newsList.link==CLList_audio){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].audioIcon;
        _anco.width=14.5;

    }else if(newsList.link==CLList_live){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].liveIcon;
        
    }

    
    if(_isStrNotNull(newsList.status)){
        self.liveStatus.text=newsList.status;
        self.liveStatus.hidden=NO;
        
    }

    [self _commentIconStyle];
}

- (void)loadDic:(NSDictionary *)dic{
    self.titleLabel.text = [dic sgrGetStringForKey:@"title"];
    [self hidenCompont];
    int linkType=[[dic sgrFGetStringForKey:@"type"] intValue];
    
    
    
    if(linkType==CLList_sliders){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].slideIcon;
        _anco.width=12;
        
    }else if(linkType==CLList_video){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].videoIcon;
        _anco.width=12;
        
    }else if(linkType==CLList_topic){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].topciIcon;
        
    }else if(linkType==CLList_audio){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].audioIcon;
        _anco.width=14.5;
        
    }else if(linkType==CLList_live){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].liveIcon;
        
    }

    [self _commentIconStyle];
}

- (void)loadCollect:(CLCollect *)collect{
    [super loadCollect:collect];
    
    //self.indexList = indexList;
    self.titleLabel.text = collect.title;
    [self hidenCompont];
    
    if(_isStrNotNull(collect.sub)){
        self.commentLable.hidden=NO;
        self.commentIcon.hidden=NO;
        self.commentLable.text=collect.sub;
    }
    
   /* if(collect.comment && collect.comment != 0){
        self.commentCountIcon.hidden=NO;
        self.commentCountLabel.hidden=NO;
        [self.commentCountLabel setText:[NSString stringWithFormat:@"%d",[collect comment]]];
    }*/
    
    if(collect.link==CLList_sliders){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].slideIcon;
        _anco.width=12;
        
    }else if(collect.link==CLList_video){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].videoIcon;
        _anco.width=12;
        
    }else if(collect.link==CLList_topic){
        _styleIcon.hidden = NO;
        _styleIcon.image=[CLGloble sharedInstance].topciIcon;
        
    }else if(collect.link==CLList_audio){
        _anco.hidden = NO;
        _anco.image=[CLGloble sharedInstance].audioIcon;
        _anco.width=14.5;
        
    }
    [self _commentIconStyle];
}

- (void)setIsRead:(BOOL)isRead{
    self.titleLabel.textColor=isRead?[UIColor grayColor]:RGB(0x4a, 0x4d, 0x53);
}



-(void)hidenCompont{
    _commentCountIcon.hidden = YES;
    _commentCountLabel.hidden = YES;
    _commentLable.hidden = YES;
    _commentIcon.hidden = YES;
    _liveStatus.hidden = YES;
    _anco.hidden = YES;
    _anco.image=nil;
    _styleIcon.hidden = YES;
    _sourceLable.hidden = YES;
    self.liveStatusLab.hidden=YES;
}

@end
